# 时间处理
# time
import time, os

print('time.altzone:', time.altzone)
print('time.timezone:', time.timezone)
a, b = time.tzname[0], time.tzname[1]
print('time.tzname:', a.encode('latin-1').decode('gbk'))
print('time.tzname:', b.encode('latin-1').decode('gbk'))
t = time.localtime()
print('time.localtime():', t)
print('time.asctime():', time.asctime())
# print(time.sleep(10))

print('time.clock():', time.clock())
print('time.gmtime():', time.gmtime())
print('time.mktime():', time.mktime(t))
print('time.time():', time.time())
print('time.strftime():', time.strftime('%Y-%m-%d %H:%M:%S'))
print('time.strptime():', time.strptime("2020-11-04 10:49:02", '%Y-%m-%d %H:%M:%S'))
# linux可用，windows无
os.environ['TZ'] = 'AEST-10AEDT-11,M10.5.0,M3.5.0'
time.tzset()
print(time.strftime('%X %x %Z'))

# datetime
from datetime import date
import datetime, time
from datetime import timedelta

d = timedelta(microseconds=-1)
print(d.days, d.seconds, d.microseconds)
today = datetime.datetime.now().date()
print(today)
yesterday = today - timedelta(days=1)
print(yesterday)
shangzhou = today - timedelta(weeks=1)

print('date(2008, 1, 1)', date(2008, 1, 1))
print(date.today())
print(date.fromtimestamp(time.time()))
d = date.fromtimestamp(time.time())
print(d.replace(day=26))
print(d.weekday())
print(d.isoweekday())
print(d.isoformat())
print(d.ctime())
print(d.strftime("%d/%m/%y"))

print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
